package Year21_Month10.day1027;

import javax.xml.soap.Node;
import java.util.LinkedList;

public class Test {
    public static void main(String[] args) {

    }

    public void print(ListNode head) {
        ListNode key = head;
        while (head != null) {
            System.out.println(head);
            head = head.next;
        }
    }

    public void printLast(ListNode head){
        ListNode key = head;
        while(head != null){
            head = head.next;
        }
        System.out.println(head.val);
    }

    public void lastTwoNdoe(ListNode head){
        ListNode slow = head;
        ListNode fast = head.next;
        while(fast.next != null){
            fast = fast.next;
            slow = slow = slow.next;
        }
        System.out.println(slow);
    }

    public void lastNNode(ListNode head,int n){
        ListNode slow = head;
        ListNode fast = head;
        int count = 0;
        while(count < n){
            fast = fast.next;
            count++;
        }
        while(fast.next != null){
            fast = fast.next;
            slow = slow.next;
        }

        System.out.println(slow);
    }

    public int  size(ListNode head){
        ListNode key = head;
        int count = 0;
        while(key != null){
            key = key.next;
            count++;
        }
        return count;
    }

    public boolean coutinue(ListNode head,int val){
        ListNode key = head;
        while(key != null){
            if(key.val == val){
                return true;
            }
            key = key.next;
        }
        return false;
    }
}
